%Declare the symbolic variables (syms)
syms cVal thetaVal phiVal u0Val sVal qVal

% f=Cstar*exp(cVal)+(k*Thetastar*exp(thetaVal)+kf*phi0*exp(phiVal))*(U0star*exp(u0Val)+...
%     s*exp(sVal)*(1-U0star*exp(u0val)))-Qstar*exp(qVal);
%f=Cstar*exp(cVal)+(k*thetaVal+kf*phi0*exp(phiVal))*(u0Val+...
%    sVal*(1-u0Val))-Qstar*exp(qVal);
f=Cstar*exp(cVal)-Qstar*exp(qVal); %Renato modified 26/08/2019 to include psyco costs

%Take symbolic derivatives
dd1 = diff(f,cVal);
dd2 = diff(f,thetaVal);
dd3 = diff(f,phiVal);
dd4 = diff(f,u0Val);
dd5 = diff(f,sVal);
dd6 = diff(f,qVal);

%Evaluates symbolic derivatives
cVal=0;  %loglin
thetaVal=Thetastar;  %linearization
phiVal=phi0;   %linearization   Renato modified 21/12
u0Val=U0star; %linearization
sVal=s;  %linearization
qVal=0; %loglin

%Substitute the symbolic values into the equations for the partial derivatives
D1=subs(dd1);
D2=subs(dd2);
D3=subs(dd3);
D4=subs(dd4);
D5=subs(dd5);
D6=subs(dd6);

% Transform symbolic into numbers (with double precision)
d1=double(D1);
d2=double(D2);
d3=double(D3);
d4=double(D4);
d5=double(D5);
d6=double(D6);


ACont(10,cLog)       = d1;
ACont(10,thetaLog)   = d2;
ACont(10,phiLog)     = d3;
ACont(10,uzeroLog)   = d4;
ACont(10,shksLog)    = d5;

ACont(10,QLog)       = d6; 

